<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/29
 * Time: 16:48
 */
class Log {
    public static function create(){
        return new self;
    }

    public function add($old_data,$new_data,$froms){
        $p = [];
        foreach ($new_data as $k=>$v){
            if(isset($old_data[$k])){
                $p[$k]= $old_data[$k];
            }
        }

        if(count($p)>0){
            $od = json_encode($p);
        }else{
            $od = json_encode($old_data);
        }
        $data["old_data"] = $od;
        $data["proc_data"] = json_encode($new_data);
        $data['froms'] = $froms;
        $data["create_date"] = time();
        $data["create_user"] = Tools::get_session("uid");
        ProcessLogModel::create()->add_($data);
    }
}